package com.apexedu.eas.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.persistence.Table;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.apexedu.eas.proxy.MyInterceptor;
import com.apexedu.eas.service.impl.ReceiveMsgImpl;
import com.apexedu.eas.thread.LogConsumer;
import com.apexedu.eas.util.ClassUtil;
import com.apexedu.eas.util.DXPTUtil;
import com.apexedu.framework.dao.BaseDao;
import com.apexedu.framework.util.ConfigUtil;

/**
 * 系统参数 Created with IntelliJ IDEA. User: ly Date: 13-11-8 Time: 上午11:11 To
 * change this template use File | Settings | File Templates.
 */

@Component("sysProperty")
public class SysProperty {
	private static Logger logger = LoggerFactory.getLogger(SysProperty.class);
	/**
	 * hibernate查询工具
	 */

	@Resource
	protected BaseDao baseDao;
	@Autowired
	public ReceiveMsgImpl receiveMsgImpl;
	public static Map<String, String> MAPING = new HashMap<String, String>();
	public static String uploadPath;
	public static String uploadUnZipPath;
	public static String hideField[];
	public static String securetKey = ConfigUtil.getString("securetKey");
	public static String reconciliationUrl = ConfigUtil
			.getString("reconciliation_url");

	@PostConstruct
	@Transactional
	void init() {
		List<Class<?>> list = ClassUtil.getClasses("com.apexedu.eas.entity");
		for (Class<?> cls : list) {
			String key = cls.getSimpleName();
			Table tab = cls.getAnnotation(Table.class);
			String value = null;
			if (tab != null)
				value = tab.name();
			MAPING.put(key, value);
			key = cls.getName();
			MAPING.put(key, value);
		}

		// 日志记录功能
		if (MyInterceptor.enable)
			new Thread(new LogConsumer(baseDao.getHibernateTemplate()
					.getSessionFactory())).start();

		uploadPath = ConfigUtil.getString("upload_path");
		uploadUnZipPath = ConfigUtil.getString("upload_unzip_path");
		hideField = ConfigUtil.getString("hideField").split(",");
		// SDKConfig.getConfig().loadPropertiesFromSrc();
		DXPTUtil.receiveMsgImpl = this.receiveMsgImpl;
		//DXPTUtil.receiveMsgImpl.getAnswer(null);

	}

}
